package com.my.spvideo.util;


import java.util.regex.Pattern;

/**
 * 用于输入参数的验证
 * @author zhangcheng
 *
 */
public class Verify {
	private static final String USERNAME_FORMAT_REG_EXP = "^[a-zA-Z0-9\u4e00-\u9fa5]+$";  
	private static final String PASSWORD_FORMAT_REG_EXP = "^[a-zA-Z0-9]+$";
	private static final String PHONENUM_FORMAT_REG_EXP = "^[0-9]+$";  
	private static final String EMAIL_FORMAT_REG_EXP = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
	
	
	public static boolean verifyUsername(String username){
		return Pattern.compile(USERNAME_FORMAT_REG_EXP).matcher(username).matches();
	}
	
	public static boolean verifyPassword(String password){
		return Pattern.compile(PASSWORD_FORMAT_REG_EXP).matcher(password).matches();
	}
	
	public static boolean verifyPhoneNum(String phoneNum){
		Pattern p = Pattern.compile(PHONENUM_FORMAT_REG_EXP);  
		return p.matcher(phoneNum).matches();
	}
	
	/**
	 * 验证性别
	 * @param consumerSex
	 * @return
	 */
	public static boolean verifySex(String consumerSex){
		return consumerSex.equals("男")||consumerSex.equals("女");
	}
	
	/**
	 * 验证邮箱
	 * @param email
	 * @return
	 */
	public static boolean verifyEmail(String email){
		Pattern p = Pattern.compile(EMAIL_FORMAT_REG_EXP);  
		return p.matcher(email).matches();
	}
	
}
